package info.xiao.dataStructrue.array;

import java.util.ArrayList;
import java.util.List;

/**
 * @Classname FindDisappearedNumbers
 * @Description 找到所有数组中消失的数字
 * @Url https://leetcode.cn/problems/find-all-numbers-disappeared-in-an-array/
 * @Date 2023/3/31 9:42
 * @Created by 晓龙Oba
 */
public class FindDisappearedNumbers {
    public static void main(String[] args) {
        int[] nums = {10, 2, 5, 10, 9, 1, 1, 4, 3, 7};
        List<Integer> list = findDisappearedNumbers(nums);
        System.out.println(list);
    }

    private static List<Integer> findDisappearedNumbers(int[] nums) {
        List<Integer> resultList = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            int index = Math.abs(nums[i]) - 1;
            nums[index] = 0 - Math.abs(nums[index]);
        }
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] > 0) {
                resultList.add(i + 1);
            }
        }
        return resultList;
    }
}
